/*
 * Copyright (C) Huawei Technologies Co., Ltd. 2021. All rights reserved.
 * Author: Huawei OS Kernel Lab
 * Create: Sun Feb 07 09:11:30 2021
 */

#ifndef __HISI_SDMA_H__
#define __HISI_SDMA_H__

#include <linux/types.h>
#include <linux/errno.h>
#include <linux/dma-direction.h>

struct sdma_copy_desc {
	unsigned long	src_addr;
	unsigned long	dst_addr;
	size_t		size;
};

struct sdma_batch_copy_desc {
	unsigned long	*src_addr;
	unsigned long	*dst_addr;
	size_t		*size;
	int		count;
};

#define IOCTL_SDMA_MEM_COPY		_IOW('s', 1, struct sdma_copy_desc)
#define IOCTL_SDMA_MEM_COPY_BATCH	_IOW('s', 2, struct sdma_batch_copy_desc)

#define SDMA_DEFAULT_STREAMID (-1)
#define SDMA_DEFAULT_SUB_STREAMID (0)

#ifdef CONFIG_HISI_SDMA

int sdma_memcpy(void *des, const void *src, size_t len);

int sdma_map_resource(int device_index, phys_addr_t paddr,
	size_t size, dma_addr_t *dma_handle, enum dma_data_direction dir);
int sdma_unmap_resource(int device_index, size_t size, dma_addr_t dma_handle, enum dma_data_direction dir);

int sdma_alloc_coherent(int device_index, size_t size, dma_addr_t *dma_handle, gfp_t gfp, void **ptr);
int sdma_free_coherent(int device_index, size_t size, dma_addr_t dma_handle, void *cpu_addr);

int sdma_kernel_mem_copy(int dev_index, dma_addr_t src_addr, dma_addr_t dst_addr, size_t size);
extern int sdma_kernel_memset(int dev_index, unsigned long addr, size_t size, int pasid, int sid, u32 pattern);

extern int sdma_alloc_coherent_nid(int device_index, size_t size, dma_addr_t *dma_handle, gfp_t gfp, void **ptr, int nid);
extern int sdma_free_coherent_nid(int device_index, size_t size, dma_addr_t dma_handle, void *cpu_addr, int nid);
extern int sdma_kernel_mem_copy_ex(int dev_index, unsigned long src_addr, int src_sid, int src_ssid,
				   unsigned long dst_addr, int dst_sid, int dst_ssid, size_t size);
#else
static inline int sdma_map_resource(int device_index, phys_addr_t paddr,
               size_t size, dma_addr_t *dma_handle, enum dma_data_direction dir)
{
	return -ENODEV;
}

static inline int sdma_unmap_resource(int device_index, size_t size, dma_addr_t dma_handle, enum dma_data_direction dir)
{
	return -ENODEV;
}

static inline int sdma_alloc_coherent(int device_index, size_t size, dma_addr_t *dma_handle, gfp_t gfp, void **ptr)
{
	return -ENODEV;
}

static inline int sdma_free_coherent(int device_index, size_t size, dma_addr_t dma_handle, void *cpu_addr)
{
	return -ENODEV;
}

static inline int sdma_kernel_mem_copy(int dev_index, dma_addr_t src_addr, dma_addr_t dst_addr, size_t size)
{
	return -ENODEV;
}

static inline int
sdma_kernel_memset(int dev_index, unsigned long addr, size_t size, int pasid, int sid, u32 pattern)
{
	return -ENODEV;
}

static inline int
sdma_alloc_coherent_nid(int device_index, size_t size, dma_addr_t *dma_handle, gfp_t gfp, void **ptr, int nid)
{
	return -ENODEV;
}

static inline int
sdma_free_coherent_nid(int device_index, size_t size, dma_addr_t dma_handle, void *cpu_addr, int nid)
{
	return -ENODEV;
}

static inline int
sdma_kernel_mem_copy_ex(int dev_index, unsigned long src_addr, int src_sid, int src_ssid,
				   unsigned long dst_addr, int dst_sid, int dst_ssid, size_t size)
{
	return -ENODEV;
}
#endif

#endif
